<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ReportsApiController extends AbstractRestfulController
{
    public function getList()
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\ReviewsFactory');
		$reviews = $userMedicineOrderTable->getAllReviewsAndRatings()->toArray();
		if(count($reviews)!=0){
				return new JsonModel(array(
					'reviews'		=> json_encode($reviews),
					'value'			=> 1,
				));
			}else{
				return new JsonModel(array(
					'reviews'		=> 	'empty',
					'value'			=> 	0,
				));
			}
    }
    public function get($id)
    {	
		
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');
		$fromDate=$data['from_date'];
		$toDate=$data['to_date'];
		$reportsType=$data['reports_type'];		
		$reports1='';$reports2='';$reports3='';$reports4='';
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		for($i=0;$i<=3;$i++){
			if($i==0){				
				$reports1 = $userMedicineOrderTable->getDatewiseReports($data,$i);
			}else if($i==1){
				$reports2 = $userMedicineOrderTable->getDatewiseReports($data,$i);
			}else if($i==2){
				$reports3 = $userMedicineOrderTable->getDatewiseReports($data,$i);
			}else if($i==3){
				$reports4 = $userMedicineOrderTable->getDatewiseReports($data,$i);
			}
		}		
		return new JsonModel(array(
			'reports1'		=> json_encode($reports1),
			'reports2'		=> json_encode($reports2),
			'reports3'		=> json_encode($reports3),
			'reports4'		=> json_encode($reports4),
		));			
    }
    public function update($order_id,$order)
    {
		
	}
		
    public function delete($id)
    {
       
    }
}